
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/31/2012 23:27:32
-- Generated from EDMX file: c:\users\mrc\documents\visual studio 2012\Projects\GestionDatos\GestionDatos\Entidades.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [aspnet-GestionDatos-20121031195624];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserProfileAccion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Acciones] DROP CONSTRAINT [FK_UserProfileAccion];
GO
IF OBJECT_ID(N'[dbo].[FK_UserProfileEntrada]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Entradas] DROP CONSTRAINT [FK_UserProfileEntrada];
GO
IF OBJECT_ID(N'[dbo].[FK_EspectaculoEntrada]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Entradas] DROP CONSTRAINT [FK_EspectaculoEntrada];
GO
IF OBJECT_ID(N'[dbo].[FK_LugarEspectaculo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Espectaculos] DROP CONSTRAINT [FK_LugarEspectaculo];
GO
IF OBJECT_ID(N'[dbo].[FK_ArtistaEspectaculo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Espectaculos] DROP CONSTRAINT [FK_ArtistaEspectaculo];
GO
IF OBJECT_ID(N'[dbo].[FK_webpages_UsersInRoles_webpages_Roles]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[webpages_UsersInRoles] DROP CONSTRAINT [FK_webpages_UsersInRoles_webpages_Roles];
GO
IF OBJECT_ID(N'[dbo].[FK_webpages_UsersInRoles_UserProfile]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[webpages_UsersInRoles] DROP CONSTRAINT [FK_webpages_UsersInRoles_UserProfile];
GO
IF OBJECT_ID(N'[dbo].[FK_EntradaNumerada_inherits_Entrada]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Entradas_EntradaNumerada] DROP CONSTRAINT [FK_EntradaNumerada_inherits_Entrada];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserProfile]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserProfile];
GO
IF OBJECT_ID(N'[dbo].[Acciones]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Acciones];
GO
IF OBJECT_ID(N'[dbo].[Entradas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Entradas];
GO
IF OBJECT_ID(N'[dbo].[Espectaculos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Espectaculos];
GO
IF OBJECT_ID(N'[dbo].[Lugares]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Lugares];
GO
IF OBJECT_ID(N'[dbo].[Artistas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Artistas];
GO
IF OBJECT_ID(N'[dbo].[webpages_Membership]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_Membership];
GO
IF OBJECT_ID(N'[dbo].[webpages_OAuthMembership]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_OAuthMembership];
GO
IF OBJECT_ID(N'[dbo].[webpages_Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_Roles];
GO
IF OBJECT_ID(N'[dbo].[Entradas_EntradaNumerada]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Entradas_EntradaNumerada];
GO
IF OBJECT_ID(N'[dbo].[webpages_UsersInRoles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_UsersInRoles];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserProfile'
CREATE TABLE [dbo].[UserProfile] (
    [UserId] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(max)  NULL
);
GO

-- Creating table 'Acciones'
CREATE TABLE [dbo].[Acciones] (
    [AccionId] int IDENTITY(1,1) NOT NULL,
    [EntidadId] int  NOT NULL,
    [TipoAccion] nvarchar(max)  NOT NULL,
    [FechaHora] datetime  NOT NULL,
    [UserId] int  NOT NULL,
    [TipoEntidad] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Entradas'
CREATE TABLE [dbo].[Entradas] (
    [EntradaId] int IDENTITY(1,1) NOT NULL,
    [Estado] nvarchar(max)  NOT NULL,
    [Precio] int  NOT NULL,
    [FechaVenta] datetime  NOT NULL,
    [UserId] int  NULL,
    [EspectaculoId] int  NOT NULL
);
GO

-- Creating table 'Espectaculos'
CREATE TABLE [dbo].[Espectaculos] (
    [EspectaculoId] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL,
    [Descripcion] nvarchar(max)  NOT NULL,
    [FechaHora] datetime  NOT NULL,
    [FechaLimite] datetime  NOT NULL,
    [Estado] nvarchar(max)  NOT NULL,
    [LugarId] int  NOT NULL,
    [ArtistaId] int  NOT NULL
);
GO

-- Creating table 'Lugares'
CREATE TABLE [dbo].[Lugares] (
    [LugarId] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL,
    [Ciudad] nvarchar(max)  NOT NULL,
    [Provincia] nvarchar(max)  NOT NULL,
    [Direccion] nvarchar(max)  NOT NULL,
    [CantGen] int  NOT NULL,
    [CantFilas] int  NOT NULL,
    [AsientosFila] int  NOT NULL
);
GO

-- Creating table 'Artistas'
CREATE TABLE [dbo].[Artistas] (
    [ArtistaId] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL,
    [Descripcion] nvarchar(max)  NOT NULL,
    [Genero] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'webpages_Membership'
CREATE TABLE [dbo].[webpages_Membership] (
    [UserId] int  NOT NULL,
    [CreateDate] datetime  NULL,
    [ConfirmationToken] nvarchar(128)  NULL,
    [IsConfirmed] bit  NULL,
    [LastPasswordFailureDate] datetime  NULL,
    [PasswordFailuresSinceLastSuccess] int  NOT NULL,
    [Password] nvarchar(128)  NOT NULL,
    [PasswordChangedDate] datetime  NULL,
    [PasswordSalt] nvarchar(128)  NOT NULL,
    [PasswordVerificationToken] nvarchar(128)  NULL,
    [PasswordVerificationTokenExpirationDate] datetime  NULL
);
GO

-- Creating table 'webpages_OAuthMembership'
CREATE TABLE [dbo].[webpages_OAuthMembership] (
    [Provider] nvarchar(30)  NOT NULL,
    [ProviderUserId] nvarchar(100)  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'webpages_Roles'
CREATE TABLE [dbo].[webpages_Roles] (
    [RoleId] int IDENTITY(1,1) NOT NULL,
    [RoleName] nvarchar(256)  NOT NULL
);
GO

-- Creating table 'Entradas_EntradaNumerada'
CREATE TABLE [dbo].[Entradas_EntradaNumerada] (
    [Fila] int  NOT NULL,
    [Asiento] int  NOT NULL,
    [EntradaId] int  NOT NULL
);
GO

-- Creating table 'webpages_UsersInRoles'
CREATE TABLE [dbo].[webpages_UsersInRoles] (
    [webpages_Roles_RoleId] int  NOT NULL,
    [UserProfile_UserId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [UserId] in table 'UserProfile'
ALTER TABLE [dbo].[UserProfile]
ADD CONSTRAINT [PK_UserProfile]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [AccionId] in table 'Acciones'
ALTER TABLE [dbo].[Acciones]
ADD CONSTRAINT [PK_Acciones]
    PRIMARY KEY CLUSTERED ([AccionId] ASC);
GO

-- Creating primary key on [EntradaId] in table 'Entradas'
ALTER TABLE [dbo].[Entradas]
ADD CONSTRAINT [PK_Entradas]
    PRIMARY KEY CLUSTERED ([EntradaId] ASC);
GO

-- Creating primary key on [EspectaculoId] in table 'Espectaculos'
ALTER TABLE [dbo].[Espectaculos]
ADD CONSTRAINT [PK_Espectaculos]
    PRIMARY KEY CLUSTERED ([EspectaculoId] ASC);
GO

-- Creating primary key on [LugarId] in table 'Lugares'
ALTER TABLE [dbo].[Lugares]
ADD CONSTRAINT [PK_Lugares]
    PRIMARY KEY CLUSTERED ([LugarId] ASC);
GO

-- Creating primary key on [ArtistaId] in table 'Artistas'
ALTER TABLE [dbo].[Artistas]
ADD CONSTRAINT [PK_Artistas]
    PRIMARY KEY CLUSTERED ([ArtistaId] ASC);
GO

-- Creating primary key on [UserId] in table 'webpages_Membership'
ALTER TABLE [dbo].[webpages_Membership]
ADD CONSTRAINT [PK_webpages_Membership]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [Provider], [ProviderUserId] in table 'webpages_OAuthMembership'
ALTER TABLE [dbo].[webpages_OAuthMembership]
ADD CONSTRAINT [PK_webpages_OAuthMembership]
    PRIMARY KEY CLUSTERED ([Provider], [ProviderUserId] ASC);
GO

-- Creating primary key on [RoleId] in table 'webpages_Roles'
ALTER TABLE [dbo].[webpages_Roles]
ADD CONSTRAINT [PK_webpages_Roles]
    PRIMARY KEY CLUSTERED ([RoleId] ASC);
GO

-- Creating primary key on [EntradaId] in table 'Entradas_EntradaNumerada'
ALTER TABLE [dbo].[Entradas_EntradaNumerada]
ADD CONSTRAINT [PK_Entradas_EntradaNumerada]
    PRIMARY KEY CLUSTERED ([EntradaId] ASC);
GO

-- Creating primary key on [webpages_Roles_RoleId], [UserProfile_UserId] in table 'webpages_UsersInRoles'
ALTER TABLE [dbo].[webpages_UsersInRoles]
ADD CONSTRAINT [PK_webpages_UsersInRoles]
    PRIMARY KEY NONCLUSTERED ([webpages_Roles_RoleId], [UserProfile_UserId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [UserId] in table 'Acciones'
ALTER TABLE [dbo].[Acciones]
ADD CONSTRAINT [FK_UserProfileAccion]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfile]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserProfileAccion'
CREATE INDEX [IX_FK_UserProfileAccion]
ON [dbo].[Acciones]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'Entradas'
ALTER TABLE [dbo].[Entradas]
ADD CONSTRAINT [FK_UserProfileEntrada]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfile]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserProfileEntrada'
CREATE INDEX [IX_FK_UserProfileEntrada]
ON [dbo].[Entradas]
    ([UserId]);
GO

-- Creating foreign key on [EspectaculoId] in table 'Entradas'
ALTER TABLE [dbo].[Entradas]
ADD CONSTRAINT [FK_EspectaculoEntrada]
    FOREIGN KEY ([EspectaculoId])
    REFERENCES [dbo].[Espectaculos]
        ([EspectaculoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EspectaculoEntrada'
CREATE INDEX [IX_FK_EspectaculoEntrada]
ON [dbo].[Entradas]
    ([EspectaculoId]);
GO

-- Creating foreign key on [LugarId] in table 'Espectaculos'
ALTER TABLE [dbo].[Espectaculos]
ADD CONSTRAINT [FK_LugarEspectaculo]
    FOREIGN KEY ([LugarId])
    REFERENCES [dbo].[Lugares]
        ([LugarId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LugarEspectaculo'
CREATE INDEX [IX_FK_LugarEspectaculo]
ON [dbo].[Espectaculos]
    ([LugarId]);
GO

-- Creating foreign key on [ArtistaId] in table 'Espectaculos'
ALTER TABLE [dbo].[Espectaculos]
ADD CONSTRAINT [FK_ArtistaEspectaculo]
    FOREIGN KEY ([ArtistaId])
    REFERENCES [dbo].[Artistas]
        ([ArtistaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ArtistaEspectaculo'
CREATE INDEX [IX_FK_ArtistaEspectaculo]
ON [dbo].[Espectaculos]
    ([ArtistaId]);
GO

-- Creating foreign key on [webpages_Roles_RoleId] in table 'webpages_UsersInRoles'
ALTER TABLE [dbo].[webpages_UsersInRoles]
ADD CONSTRAINT [FK_webpages_UsersInRoles_webpages_Roles]
    FOREIGN KEY ([webpages_Roles_RoleId])
    REFERENCES [dbo].[webpages_Roles]
        ([RoleId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UserProfile_UserId] in table 'webpages_UsersInRoles'
ALTER TABLE [dbo].[webpages_UsersInRoles]
ADD CONSTRAINT [FK_webpages_UsersInRoles_UserProfile]
    FOREIGN KEY ([UserProfile_UserId])
    REFERENCES [dbo].[UserProfile]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_webpages_UsersInRoles_UserProfile'
CREATE INDEX [IX_FK_webpages_UsersInRoles_UserProfile]
ON [dbo].[webpages_UsersInRoles]
    ([UserProfile_UserId]);
GO

-- Creating foreign key on [EntradaId] in table 'Entradas_EntradaNumerada'
ALTER TABLE [dbo].[Entradas_EntradaNumerada]
ADD CONSTRAINT [FK_EntradaNumerada_inherits_Entrada]
    FOREIGN KEY ([EntradaId])
    REFERENCES [dbo].[Entradas]
        ([EntradaId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------